from pyglons.state import State, StateManager, Stop
from pyglons import g
from pyglons.lib.window import Window

import pyglet

__all__ = ['App']

class App(StateManager, State):
    """ Base pyglons application. 
    """

    # the default window class that will be generated
    default_window_class = Window
    
    def __init__(self, window=None):
        StateManager.__init__(self)
        self.window = window
        g.app = self

    def init_video(self):
        """ create a window object """
        self.window = self.create_window(g.config['window']['width'], 
                                        g.config['window']['height'])

    def create_window(self, *args, **kwargs):
        return self.default_window_class(*args, **kwargs)

    def run(self):
        """ run the application """
        try:
            self.on_enter()
            pyglet.app.run()
        except Stop:
            pass
        finally:
            self.on_exit()


 

